<?php

namespace App\Http\Controllers;

use App\Business\BLL\UserDaliyPointBLL;
use App\Jobs\SettlementSectPoint;
use App\Models\ShareLog;
use App\Models\WechatUser;
use Illuminate\Http\Request;

class ShareController extends Controller
{
    public function shareApp()
    {
        $userId = request()->input('user_id', 0);
        if ($userId === 0) {
            return response()->json([
                'recode' => 0,
                'msg' => "没有用户",
            ]);
        }
        $page = request()->input('page', '');
        $pageId = request()->input('page_id', 0);

        $point = config('set.share_point');

        $point = UserDaliyPointBLL::getUserPoint($userId, $point);
        if ($point > 0) {
            $user = WechatUser::find($userId);
            if ($user) {
                $user->point += $point;
                $user->save();
            }
            $sectMatchPoint = config('set.share_point');
            SettlementSectPoint::dispatch($userId, $sectMatchPoint);
        }
        //新增分享记录
        $shareLog = new ShareLog;
        $shareLog->user_id = $userId;
        $shareLog->page = $page;
        $shareLog->page_id = $pageId;
        $shareLog->save();

        return response()->json([
            'recode' => 1,
            'msg' => "活跃增加",
        ]);

    }
}
